package cn.wolfcode.luowowo.article.service.impl;

import cn.wolfcode.luowowo.article.domain.Region;
import cn.wolfcode.luowowo.article.mapper.RegionMapper;
import cn.wolfcode.luowowo.article.query.RegionQuery;
import cn.wolfcode.luowowo.article.service.IRegionService;
import com.alibaba.dubbo.config.annotation.Reference;
import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@Service
public class RegionServiceImpl implements IRegionService{

    @Autowired
    private RegionMapper mapper;

    @Override
    public PageInfo query(RegionQuery qo) {
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize());
        List<Region> list = mapper.queryForList();
        return new PageInfo(list);
    }

    @Override
    public void saveOrUpdate(Region region) {
        if(region.getId()==null){
            mapper.insert(region);  //没有id的话保存操作
        }else {
            mapper.updateByPrimaryKey(region);  //有id的话更新操作
        }
    }

    @Override
    public Region get(Long rid) {
        Region region = mapper.selectByPrimaryKey(rid);
        return region;
    }

    @Override
    public List<Region> queryHotRegions() {
        return mapper.selectHotRegions();
    }

    @Override
    public void changeHotValue(boolean hot, Long id) {
        mapper.changeHotValue(hot, id);
    }
}
